package com.solcoo.dao;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Repository;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.solcoo.json.VIPJson;
import com.solcoo.pojo.TempSeller;
import com.solcoo.pojo.ZhangHu;

@Repository
public class ZhangHuDao {

	@Resource
	private SqlMapClient sqlMapClient;
	
    // 设置账户的“是否关注”
    public boolean setGZ(int shanghuid, int gerenid, String shifougz) throws SQLException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("sellerId", shanghuid);
        map.put("userId", gerenid);
        map.put("shifougz", shifougz);
        return sqlMapClient.update("updateAccountWithGZ", map) == 1 ? true :false;
    }

    // 根据商户ID和个人ID获取账户
    public ZhangHu query(int shanghuid, int gerenid) throws SQLException {
    	Map<String, Object> param = new HashMap<String, Object>();
    	param.put("shanghuid", shanghuid);
    	param.put("gerenid", gerenid);
        return (ZhangHu) sqlMapClient.queryForObject("selectAccount", param);
    }

    // 个人查询会员商户列表
    public List<TempSeller> querySellerInfoByUserId(int gerenid,int youbiao) throws SQLException {
    	Map<String, Object> param = new HashMap<String, Object>();
    	param.put("yonghuid", gerenid);
        if(youbiao > 0)
        	param.put("youbiao", youbiao);
        return sqlMapClient.queryForList("selectSellersByUserId", param);
    }

    public void add(ZhangHu zh) throws SQLException {
        sqlMapClient.insert("inserAccount", zh);
    }

    public boolean update(ZhangHu zh) throws SQLException {
        int target = sqlMapClient.update("rechargeUpdate", zh);
        return target > 0 ? true : false;
    }

    // 根据shanghuid查找对应所有的账户
     public List<ZhangHu> queryListByShid(int shanghuid) throws SQLException {
         return sqlMapClient.queryForList("selectAccountsByShid", shanghuid);
     }
     
     // 根据gerenid查找对应所有的账户
     public List<ZhangHu> queryListByGrid(int gerenid) throws SQLException {
         return sqlMapClient.queryForList("selectAccountsByGrid", gerenid);
     }
     
     // 根据gerenid查找首次充值50以上的shanghuid
     public Integer queryShidA(int gerenid) throws SQLException {
         return (Integer)sqlMapClient.queryForObject("queryShidA", gerenid);
     }

	public int getMemberNum(Integer merchantId) throws SQLException {
		return (Integer)sqlMapClient.queryForObject("selectMemberNum", merchantId);
	}

	public List<VIPJson> getVIPListByShanghuid(int shanghuid) throws SQLException {
		return sqlMapClient.queryForList("getVIPListByShanghuid", shanghuid);
	}

	public int getShNQSum(Map<String, Object> param) throws SQLException {
		return (Integer)sqlMapClient.queryForObject("selectZHShNQSum", param);
	}

	public int getGrNQSum(Map<String, Object> param) throws SQLException {
		return (Integer)sqlMapClient.queryForObject("selectZHGrNQSum", param);
	}

	public void updateNQCount(Map<String, Object> param) throws SQLException {
		sqlMapClient.update("updateZHNQCount", param);
	}
}
